package com.space.loboratory.consumer.scan;

import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.util.ClassUtils;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/5/17 11:46 上午
 */
public class Candidate {
//    private Set<BeanDefinition> scanCandidateComponents(String basePackage) {
//        LinkedHashSet candidates = new LinkedHashSet();
//        try {
//            String packageSearchPath = "classpath*:" + ClassUtils.convertClassNameToResourcePath(new StandardEnvironment().resolveRequiredPlaceholders(basePackage)) + "/**/*.class";
//            Resource[] resources = new PathMatchingResourcePatternResolver().getResources(packageSearchPath);
//            int var8 = resources.length;
//
//            for (Resource resource : resources) {
//                if (resource.isReadable()) {
//                    try {
//                        MetadataReader metadataReader = new CachingMetadataReaderFactory().getMetadataReader(resource);
//                        if (this.isCandidateComponent(metadataReader)) {
//                            ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
//                            sbd.setSource(resource);
//                            if (this.isCandidateComponent((AnnotatedBeanDefinition) sbd)) {
//                                candidates.add(sbd);
//                            } else if (debugEnabled) {
//                                this.logger.debug("Ignored because not a concrete top-level class: " + resource);
//                            }
//                        } else if (traceEnabled) {
//                            this.logger.trace("Ignored because not matching any filter: " + resource);
//                        }
//                    } catch (Throwable var13) {
//                        throw new BeanDefinitionStoreException("Failed to read candidate component class: " + resource, var13);
//                    }
//                } else if (traceEnabled) {
//                    this.logger.trace("Ignored because not readable: " + resource);
//                }
//            }
//
//            return candidates;
//        } catch (IOException var14) {
//            throw new BeanDefinitionStoreException("I/O failure during classpath scanning", var14);
//        }
//    }
}
